package Test;

public class test2 {
    //牛客 合并两个有序数组(后台会自动将第一个数组扩容并取第一个数组进行判断)
    public static void main(String[] args) {
        int[] arr1 = {1, 3, 5};
        int[] arr2 = {2, 4, 6};
        int m = arr1.length;
        int n = arr2.length;
        merge(arr1, m, arr2, n);
    }

    private static void merge(int[] arr1, int m, int[] arr2, int n) {
        int i = m - 1;
        int j = n - 1;
        int k = m + n - 1;
        while(i>=0 && j>=0){
            if(arr1[i]>arr2[j]){
                arr1[k]=arr1[i];
                k--;
                i--;
            }else{
                arr1[k]=arr2[j];
                k--;
                j--;
            }
        }
        while(j>=0){
            arr1[k]=arr2[j];
            k--;
            j--;
        }

    }

}
